package com.example.myapplication.apter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RatingBar;
import android.widget.RelativeLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.example.myapplication.Config.TokenBean;
import com.example.myapplication.R;
import com.example.myapplication.ShuJu.AlacarteBean;
import com.example.myapplication.ShuJu.StorereviewBean;

import java.util.List;

public class Storereviewapter extends RecyclerView.Adapter<Storereviewapter.MyHolder>{
    private Context context;
    private List<StorereviewBean.RowsBean> list;

    public Storereviewapter(Context context, List<StorereviewBean.RowsBean> list) {
        this.context = context;
        this.list = list;
    }

    @NonNull
    @Override
    public Storereviewapter.MyHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_storereview,null);
        return new Storereviewapter.MyHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull Storereviewapter.MyHolder holder, int position) {
        try {
            Glide.with(context).load(TokenBean.IP+list.get(position).getAvatar()).into(holder.avatar);
            holder.nickName.setText(list.get(position).getNickName());
            holder.commentDate.setText(list.get(position).getCommentDate());
            holder.rating.setRating(Float.valueOf(list.get(position).getScore()));
            holder.content.setText(list.get(position).getContent());
            holder.replyContent.setText(list.get(position).getReplyContent());
        } catch (Exception e) {
            e.printStackTrace();
        }

    }

    @Override
    public int getItemCount() {
        return list == null ? 0 : list.size();
    }

    class MyHolder extends RecyclerView.ViewHolder {
        ImageView avatar;
        private final TextView replyContent;
        private final TextView content;
        private final RatingBar rating;
        private final TextView commentDate;
        private final TextView nickName;


        public MyHolder(@NonNull View itemView) {
            super(itemView);
            avatar = itemView.findViewById(R.id.avatar);
            nickName = itemView.findViewById(R.id.nickName);
            commentDate = itemView.findViewById(R.id.commentDate);
            rating = itemView.findViewById(R.id.rating);
            content = itemView.findViewById(R.id.content);
            replyContent = itemView.findViewById(R.id.replyContent);
        }
    }
}




